<?php


namespace app\ymsh\controller;


use app\admin\model\order\Movie as MovieModel;
use app\admin\model\order\Takeout as TakeoutModel;
use app\common\service\tool\grid\Format;
use app\Query;
use app\model\MovieOrder;
use app\model\TakeoutOrder;
use app\ymsh\model\Order as OrderModel;
use think\Exception;

class Order extends BaseController
{
    /**
     * 统一订单
     */
    public function unionList()
    {
        $params = request()->all();
        $model = new OrderModel();
        $data = $model->unionList($params);
        return $data;
    }

    /**
     * 外卖订单
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function takeout()
    {
        if (\app\common\facade\auth\Auth::isAdmin()){
            $model = new TakeoutModel;
            return $model->getList(input('post.'));
        }

        if (\app\common\facade\auth\Auth::isMerchant()){
            $model = new \app\agent\model\order\Takeout;
            $data = input('post.');
            return $model->getList($data);
        }

    }

    /**
     * 电影订单
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function movie()
    {
        if (\app\common\facade\auth\Auth::isAdmin()){
            $model = new MovieModel;
            return $model->getList(input('post.'));
        }

        if (\app\common\facade\auth\Auth::isMerchant()){//商户
            $model = new \app\agent\model\order\Movie;
            $data = input('post.');
            return $model->getList($data);
        }

    }


    public function getWith()
    {
        return [
            'agent' => function (\think\db\Query $query) {
                $query->with(['agentExtend' => function (\think\db\Query $query) {
                    $query->field('agent_id,app_name,merchant_name,merchant_id');
                }])->field('company_name,id');
            }
        ];
    }

}